unit upasserversocashdrawer0101;
{$I LogOption.txt}

interface
uses
  ActiveX,    // this is OPOS, therefore this is for Windows,
              // don't bother compiling in Linux 
  SysUtils,
  upasserversocashdrawer,
  OposCashDrawer_CCO_TLB;

type
  EOupasserversocashdrawer0101 = class(EOupasserversocashdrawer)
  private
    // The OPOS CCO Interface
    FOPOSCCO: TOPOSCashDrawer;

    FOPOSLDN: String;

  protected
    // Common Properties getter/setter
    function getAutoDisable: Boolean; override;
    function getBinaryConversion: Integer; override;
    function getCapCompareFirmwareVersion: Boolean; override;
    function getCapPowerReporting: Integer; override;
    function getCapStatisticsReporting: Boolean; override;
    function getCapUpdateFirmware: Boolean; override;
    function getCapUpdateStatistics: Boolean; override;
    function getCheckHealthText: String; override;
    function getClaimed: Boolean; override;
    function getControlObjectDescription: String; override;
    function getControlObjectVersion: Integer; override;
    function getDataCount: Boolean; override;
    function getDataEventEnabled: Boolean; override;
    function getDeviceControlDescription: String; override;
    function getDeviceControlVersion: Integer; override;
    function getDeviceDescription: String; override;
    function getDeviceEnabled: Boolean; override;
    function getDeviceName: String; override;
    function getDeviceServiceDescription: String; override;
    function getDeviceServiceVersion: Integer; override;
    function getFreezeEvents: Boolean; override;
    function getOpenResult: Integer; override;
    function getOutpuID: Integer; override;
    function getPhysicalDeviceDescription: String; override;
    function getPhysicalDeviceName: String; override;
    function getPowerNotify: Integer; override;
    function getPowerState: Integer; override;
    function getResultCode: Integer; override;
    function getResultCodeExtended: Integer; override;
    function getServiceObjectDescription: String; override;
    function getServiceObjectVersion: Integer; override;
    function getState: Integer; override;
    procedure setAutoDisable(Value: Boolean); override;
    procedure setBinaryConversion(Value: Integer); override;
    procedure setDataEventEnabled(Value: Boolean); override;
    procedure setDeviceEnabled(Value: Boolean); override;
    procedure setFreezeEvents(Value: Boolean); override;
    procedure setPowerNotify(Value: Integer); override;

    // CashDrawer Properties getter/setter
    function getCapStatus: WordBool; override;
    function getCapStatusMultiDrawerDetect: WordBool; override;
    function getDrawerOpened: WordBool; override;

  public
    // Common Methods
    function CheckHealth(Level: Integer): Integer; override;
    function ClaimDevice(Timeout: Integer): Integer; override;
    function ClearInput: Integer; override;
    function ClearInputProperties: Integer; override;
    function ClearOutput: Integer; override;
    function Close: Integer; override;
    function CompareFirmwareVersion(const FirmwareFileName: WideString; out pResult: Integer): Integer; override;
    function DirectIO(Command: Integer; var pData: Integer; var pString: WideString): Integer; override;
    function Open(const DeviceName: String): Integer; override;
    function ReleaseDevice: Integer; override;
    function ResetStatistics(const StatisticsBuffer: WideString): Integer; override;
    function RetrieveStatistics(var pStatisticsBuffer: WideString): Integer; override;
    function UpdateFirmware(const FirmwareFileName: WideString): Integer; override;
    function UpdateStatistics(const StatisticsBuffer: WideString): Integer; override;

    // CashDrawer Methods
    function OpenDrawer: Integer; override;
    function WaitForDrawerClose(BeepTimeout: Integer; BeepFrequency: Integer; BeepDuration: Integer; BeepDelay: Integer): Integer;  override;

    constructor Create(DeviceName: String; Instance: Integer = 1; LDN: String = '');
    destructor Destroy; override;

  end;

implementation
uses
  AuditLog,
  opos,
  oposutils,
  upasco;

function EOupasserversocashdrawer0101.CheckHealth(Level: Integer): Integer;
begin
  Result := FOPOSCCO.CheckHealth(Level);
end;

function EOupasserversocashdrawer0101.ClaimDevice(Timeout: Integer): Integer;
begin
  Result := FOPOSCCO.ClaimDevice(Timeout);
end;

function EOupasserversocashdrawer0101.ClearInput: Integer;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.ClearInput', 'OPOS_E_FAILURE');
  {$ENDIF}

  Result :=  opos.OPOS_E_FAILURE;
end;

function EOupasserversocashdrawer0101.ClearInputProperties: Integer;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.ClearInputProperties', 'OPOS_E_FAILURE');
  {$ENDIF}

  Result :=  opos.OPOS_E_FAILURE;
end;

function EOupasserversocashdrawer0101.ClearOutput: Integer;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.ClearOutput', 'OPOS_E_FAILURE');
  {$ENDIF}

  Result :=  opos.OPOS_E_FAILURE;
end;

function EOupasserversocashdrawer0101.Close: Integer;
begin
  Result := FOPOSCCO.Close;
end;

function EOupasserversocashdrawer0101.DirectIO(Command: Integer; var pData: Integer; var pString: WideString): Integer;
begin
  Result := FOPOSCCO.DirectIO(Command, pData, pString);
end;

function EOupasserversocashdrawer0101.Open(const DeviceName: String): Integer;
begin
  Result := FOPOSCCO.Open(DeviceName);
end;

function EOupasserversocashdrawer0101.ReleaseDevice: Integer;
begin
  Result := FOPOSCCO.ReleaseDevice;
end;

function EOupasserversocashdrawer0101.OpenDrawer: Integer;
begin
  try
    if FOPOSCCO.OpenResult <> opos.OPOS_SUCCESS then
      FOPOSCCO.Open(FOPOSLDN);

    {$IFDEF LOGUNITTEST}
    AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.OpenDrawer', 'FOpenStatus="' + IntToStr(FOPOSCCO.OpenResult) + '"');
    {$ENDIF}

    if FOPOSCCO.OpenResult = opos.OPOS_SUCCESS then
      if not FOPOSCCO.Claimed then
        FOPOSCCO.ClaimDevice(1000);

    {$IFDEF LOGUNITTEST}
    AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.OpenDrawer', 'FClaimStatus="' + IntToStr(FOPOSCCO.ResultCode) + '"');
    {$ENDIF}

    if FOPOSCCO.Claimed then
      if not FOPOSCCO.DeviceEnabled then
        FOPOSCCO.DeviceEnabled := True;

    if FOPOSCCO.DeviceEnabled then begin
      {$IFDEF LOGUNITTEST}
      AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.OpenDrawer', 'DeviceEnabled="TRUE"');
      {$ENDIF}

      try
        {$IFDEF LOGUNITTEST}
          Result := FOPOSCCO.OpenDrawer;
          AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.OpenDrawer', 'FOPOSCCO.OpenDrawer Result="' + IntToStr(Result) + '"');
        {$ELSE}
          Result := FOPOSCCO.OpenDrawer;
        {$ENDIF}
      finally
        // do not disable, you will not receive events
        //FOPOSCCO.DeviceEnabled := False;
        FOPOSCCO.ReleaseDevice;
      end;
    end
    else begin
      Result := OPOS.OPOS_E_DISABLED;
      {$IFDEF LOGUNITTEST}
      AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.OpenDrawer', 'DeviceEnabled="TRUE"');
      {$ENDIF}
    end

  except
    on E: Exception do begin
      Result := OPOS.OPOS_E_FAILURE;
      AuditLog.EventLog(AuditLog.etException, EOupasserversocashdrawer0101.ClassName, TOPOSCashDrawer.ClassName + ' ' + E.Message);
      Halt(0);
    end;
  end;
end;

function EOupasserversocashdrawer0101.getAutoDisable: Boolean;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getAutoDisable', 'OPOS_E_FAILURE');
  {$ENDIF}

  Result := False; //opos.OPOS_E_FAILURE;
end;

function EOupasserversocashdrawer0101.getBinaryConversion: Integer;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getBinaryConversion', '');
  {$ENDIF}

  Result := FOPOSCCO.BinaryConversion;
end;

function EOupasserversocashdrawer0101.getCapStatus: WordBool;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getCapStatus', '');
  {$ENDIF}

  Result := FOPOSCCO.CapStatus;
end;

function EOupasserversocashdrawer0101.getCapPowerReporting: Integer;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getCapPowerReporting', '');
  {$ENDIF}

  Result := FOPOSCCO.CapPowerReporting;
end;

function EOupasserversocashdrawer0101.getCapStatusMultiDrawerDetect: WordBool;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getCapStatusMultiDrawerDetect', '');
  {$ENDIF}

  Result := FOPOSCCO.CapStatusMultiDrawerDetect;
end;

function EOupasserversocashdrawer0101.getCapStatisticsReporting: Boolean;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getCapStatisticsReporting', '');
  {$ENDIF}

  Result := FOPOSCCO.CapStatisticsReporting;
end;

function EOupasserversocashdrawer0101.getCapUpdateStatistics: Boolean;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getCapUpdateStatistics', '');
  {$ENDIF}

  Result := FOPOSCCO.CapUpdateStatistics;
end;

function EOupasserversocashdrawer0101.getCapCompareFirmwareVersion: Boolean;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getCapCompareFirmwareVersion', '');
  {$ENDIF}

  Result := FOPOSCCO.CapCompareFirmwareVersion;
end;

function EOupasserversocashdrawer0101.getCapUpdateFirmware: Boolean;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getCapUpdateFirmware', '');
  {$ENDIF}

  Result := FOPOSCCO.CapUpdateFirmware;
end;

function EOupasserversocashdrawer0101.getDrawerOpened: WordBool;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getDrawerOpened', '');
  {$ENDIF}

  Result := FOPOSCCO.DrawerOpened;
end;

function EOupasserversocashdrawer0101.getOpenResult: Integer;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getOpenResult', '');
  {$ENDIF}

  Result := FOPOSCCO.OpenResult;
end;

function EOupasserversocashdrawer0101.getOutpuID: Integer;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getOutpuID', 'OPOS_E_FAILURE');
  {$ENDIF}

  Result := opos.OPOS_E_FAILURE;
end;

function EOupasserversocashdrawer0101.getPhysicalDeviceDescription: String;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getPhysicalDeviceDescription', '');
  {$ENDIF}

//  Result := FOPOSCCO.;
end;

function EOupasserversocashdrawer0101.getPhysicalDeviceName: String;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getPhysicalDeviceName', '');
  {$ENDIF}

//  Result := FOPOSCCO.;
end;

function EOupasserversocashdrawer0101.getCheckHealthText: String;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getCheckHealthText', '');
  {$ENDIF}

  Result := FOPOSCCO.CheckHealthText;
end;

function EOupasserversocashdrawer0101.getClaimed: Boolean;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getClaimed', '');
  {$ENDIF}

  Result := FOPOSCCO.Claimed;
end;

function EOupasserversocashdrawer0101.getResultCode: Integer;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getResultCode', '');
  {$ENDIF}

  Result := FOPOSCCO.ResultCode;
end;

function EOupasserversocashdrawer0101.getResultCodeExtended: Integer;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getResultCodeExtended', '');
  {$ENDIF}

  Result := FOPOSCCO.ResultCodeExtended;
end;

function EOupasserversocashdrawer0101.getState: Integer;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getState', '');
  {$ENDIF}

  Result := FOPOSCCO.State;
end;

function EOupasserversocashdrawer0101.getControlObjectDescription: String;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getControlObjectDescription', '');
  {$ENDIF}

  Result := FOPOSCCO.ControlObjectDescription;
end;

function EOupasserversocashdrawer0101.getControlObjectVersion: Integer;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getControlObjectVersion', '');
  {$ENDIF}

  Result := FOPOSCCO.ControlObjectVersion;
end;

function EOupasserversocashdrawer0101.getDataCount: Boolean;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getDataCount', 'OPOS_E_FAILURE');
  {$ENDIF}

  Result := False;
end;

function EOupasserversocashdrawer0101.getDataEventEnabled: Boolean;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getDataEventEnabled', 'OPOS_E_FAILURE');
  {$ENDIF}

  Result := False;
end;

function EOupasserversocashdrawer0101.getDeviceControlDescription: String;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getDeviceControlDescription', 'OPOS_E_FAILURE');
  {$ENDIF}

  Result := '';
end;

function EOupasserversocashdrawer0101.getDeviceControlVersion: Integer;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getDeviceControlVersion', 'OPOS_E_FAILURE');
  {$ENDIF}

  Result := opos.OPOS_E_FAILURE;
end;

function EOupasserversocashdrawer0101.getServiceObjectDescription: String;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getServiceObjectDescription', '');
  {$ENDIF}

  Result := FOPOSCCO.ServiceObjectDescription;
end;

function EOupasserversocashdrawer0101.getServiceObjectVersion: Integer;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getServiceObjectVersion', '');
  {$ENDIF}

  Result := FOPOSCCO.ServiceObjectVersion;
end;

function EOupasserversocashdrawer0101.getDeviceDescription: String;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getDeviceDescription', '');
  {$ENDIF}

  Result := FOPOSCCO.DeviceDescription;
end;

function EOupasserversocashdrawer0101.getDeviceName: String;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getDeviceName', '');
  {$ENDIF}

  Result := FOPOSCCO.DeviceName;
end;

function EOupasserversocashdrawer0101.getDeviceServiceDescription: String;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getDeviceServiceDescription', '');
  {$ENDIF}

  Result := '';
end;

function EOupasserversocashdrawer0101.getDeviceServiceVersion: Integer;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getDeviceServiceVersion', 'OPOS_E_FAILURE');
  {$ENDIF}

  Result := opos.OPOS_E_FAILURE;
end;

function EOupasserversocashdrawer0101.getPowerState: Integer;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getPowerState', '');
  {$ENDIF}

  Result := FOPOSCCO.PowerState;
end;

function EOupasserversocashdrawer0101.getDeviceEnabled: Boolean;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getDeviceEnabled', '');
  {$ENDIF}

  Result := FOPOSCCO.DeviceEnabled;
end;

procedure EOupasserversocashdrawer0101.setDeviceEnabled(Value: Boolean);
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.setDeviceEnabled', '');
  {$ENDIF}

  FOPOSCCO.DeviceEnabled := Value;
end;

function EOupasserversocashdrawer0101.getFreezeEvents: Boolean;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getFreezeEvents', '');
  {$ENDIF}

  Result := FOPOSCCO.FreezeEvents;
end;

procedure EOupasserversocashdrawer0101.setFreezeEvents(Value: Boolean);
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.setFreezeEvents', '');
  {$ENDIF}

  FOPOSCCO.FreezeEvents := Value;
end;

procedure EOupasserversocashdrawer0101.setAutoDisable(Value: Boolean);
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.setAutoDisable', '');
  {$ENDIF}

//  FOPOSCCO.au := Value;
end;

procedure EOupasserversocashdrawer0101.setBinaryConversion(Value: Integer);
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.setBinaryConversion', '');
  {$ENDIF}

  FOPOSCCO.BinaryConversion := Value;
end;

procedure EOupasserversocashdrawer0101.setDataEventEnabled(Value: Boolean);
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.setDataEventEnabled', '');
  {$ENDIF}

//  FOPOSCCO. := Value;
end;

function EOupasserversocashdrawer0101.getPowerNotify: Integer;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.getPowerNotify', '');
  {$ENDIF}

  Result := FOPOSCCO.PowerNotify;
end;

procedure EOupasserversocashdrawer0101.setPowerNotify(Value: Integer);
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.setPowerNotify', '');
  {$ENDIF}

  FOPOSCCO.PowerNotify := Value;
end;

function EOupasserversocashdrawer0101.WaitForDrawerClose(BeepTimeout: Integer; BeepFrequency: Integer; BeepDuration: Integer; BeepDelay: Integer): Integer;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.WaitForDrawerClose', '');
  {$ENDIF}

  Result := FOPOSCCO.WaitForDrawerClose(BeepTimeout, BeepFrequency, BeepDuration, BeepDelay);
end;

function EOupasserversocashdrawer0101.ResetStatistics(const StatisticsBuffer: WideString): Integer;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.ResetStatistics', '');
  {$ENDIF}

  Result := FOPOSCCO.ResetStatistics(StatisticsBuffer);
end;

function EOupasserversocashdrawer0101.RetrieveStatistics(var pStatisticsBuffer: WideString): Integer;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.RetrieveStatistics', '');
  {$ENDIF}

  Result := FOPOSCCO.RetrieveStatistics(pStatisticsBuffer);
end;

function EOupasserversocashdrawer0101.UpdateStatistics(const StatisticsBuffer: WideString): Integer;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.UpdateStatistics', '');
  {$ENDIF}

  Result := FOPOSCCO.UpdateStatistics(StatisticsBuffer);
end;

function EOupasserversocashdrawer0101.CompareFirmwareVersion(const FirmwareFileName: WideString; out pResult: Integer): Integer;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.CompareFirmwareVersion', '');
  {$ENDIF}

  Result := FOPOSCCO.CompareFirmwareVersion(FirmwareFileName, pResult);
end;

function EOupasserversocashdrawer0101.UpdateFirmware(const FirmwareFileName: WideString): Integer;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.UpdateFirmware', '');
  {$ENDIF}

  Result := FOPOSCCO.UpdateFirmware(FirmwareFileName);
end;

constructor EOupasserversocashdrawer0101.Create(DeviceName: String; Instance: Integer = 1; LDN: String = '');
begin
  CoInitialize(Nil);

  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.Create', 'DeviceName="' + DeviceName + '"');
  {$ENDIF}

  Inherited Create(DeviceName);

  try
    FOPOSCCO := TOPOSCashDrawer.Create(Nil);
  except
    on E: Exception do begin
      AuditLog.EventLog(AuditLog.etException, EOupasserversocashdrawer0101.ClassName, TOPOSCashDrawer.ClassName + ' ' + E.Message);
    end;
  end;

  if LDN = '' then
    FOPOSLDN := oposutils.getLDN('\SOFTWARE\OLEforRetail\ServiceOPOS\CashDrawer', Instance)
  else
    FOPOSLDN := LDN;
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.Create', 'FOPOSLDN="' + FOPOSLDN + '"');
  {$ENDIF}

  FOPOSCCO.OnDirectIOEvent := OnDirectIOEvent;
  FOPOSCCO.OnStatusUpdateEvent := OnStatusUpdateEvent;

  try
    FOPOSCCO.Open(FOPOSLDN);
  except
    on E: Exception do begin
      AuditLog.EventLog(AuditLog.etException, EOupasserversocashdrawer0101.ClassName, TOPOSCashDrawer.ClassName + ' ' + E.Message);
    end;
  end;
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.Create', 'Open="' + IntToStr(FOPOSCCO.OpenResult) + '"');
  {$ENDIF}

  try
    FOPOSCCO.ReleaseDevice;
  except
    on E: Exception do begin
      AuditLog.EventLog(AuditLog.etException, EOupasserversocashdrawer0101.ClassName, TOPOSCashDrawer.ClassName + ' ' + E.Message);
    end;
  end;
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.Create', 'ReleaseDevice="' + IntToStr(FOPOSCCO.ResultCode) + '"');
  {$ENDIF}
end;

destructor EOupasserversocashdrawer0101.Destroy;
begin
  try
    FOPOSCCO.Close;
  except
    on E: Exception do begin
      AuditLog.EventLog(AuditLog.etException, EOupasserversocashdrawer0101.ClassName, TOPOSCashDrawer.ClassName + ' ' + E.Message);
    end;
  end;
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.Destroy', 'Close="' + IntToStr(FOPOSCCO.ResultCode) + '"');
  {$ENDIF}

  FOPOSCCO.Free;

  Inherited;
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, EOupasserversocashdrawer0101.ClassName + '.Destroy', '');
  {$ENDIF}

  CoUninitialize;
end;

end.
